package cn.xzzz2020.demo.aspect;

import cn.xzzz2020.XJynWeb.aop.annotation.Aspect;
import cn.xzzz2020.XJynWeb.aop.annotation.Order;
import cn.xzzz2020.XJynWeb.aop.aspect.DefaultAspect;
import lombok.extern.slf4j.Slf4j;

import java.lang.reflect.Method;

/**
 * AOP切入测试
 * @author xzzz2020
 * @version 1.0
 * @date 2020/8/9 16:07
 */
@Aspect(pointcut = "execution(* cn.xzzz2020.demo.controller..*.*(..))")
@Order
@Slf4j
public class ControllerTimeCalculatorAspect extends DefaultAspect {
    private long time;
    @Override
    public void before(Class<?> targetClass, Method method, Object[] args) throws Throwable {
        log.info("开始计时，执行的类是[{}],执行的方法是[{}],参数是[{}]",targetClass.getName(),method.getName(),args);
        time = System.currentTimeMillis();
    }

    @Override
    public Object afterReturning(Class<?> targetClass, Method method, Object[] args, Object returnValue) throws Throwable {
        time = System.currentTimeMillis()-time;
        log.info("开始结束，执行的类是[{}],执行的方法是[{}],参数是[{}],方法执行了[{}]",
                targetClass.getName(),method.getName(),args,time);
        return returnValue;
    }
}
